﻿using MediatR;
using Purchase.ApiS.Dto;
using Purchase.ApiS.ListDisplay.Command.Supplier;
using Purchase.Domian.Model;
using Purchase.ErrorCode;
using Purchase.Infrastructrue.Implenment;

namespace Purchase.ApiS.ListDisplay.Hanlder.Supplier
{
    public class PurchasedMaterialsCommandHanlder : IRequestHandler<PurchasedMaterialsCommand, ApiResult<MaterialInfo>>
    {
        public readonly IBaseRepostity<MaterialInfo> _materialRepostity;
        public ILogger<PurchasedMaterialsCommandHanlder> logger;

        public PurchasedMaterialsCommandHanlder(IBaseRepostity<MaterialInfo> materialRepostity, ILogger<PurchasedMaterialsCommandHanlder> logger)
        {
            _materialRepostity = materialRepostity;
            this.logger = logger;
        }
        /// <summary>
        /// 获取采购信息列表方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        public Task<ApiResult<MaterialInfo>> Handle(PurchasedMaterialsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<MaterialInfo> result = new ApiResult<MaterialInfo>();
            try
            {
                var list = _materialRepostity.GetAll().ToList();
                result.Code = ApiEume.Success;
                result.Datas = list.ToList();
                result.Msg = "获取采购信息列表成功";


                
            }
            catch (Exception ex)
            {

            }
            return Task.FromResult(result);
        }
    }
}
